//
//  UserInfo.cpp
//  Chart
//
//  Created by CaoJun on 15/2/4.
//
//
#include "UserInfo.h"


using namespace ytx;
using namespace std;

static UserInfo * userInfoInstance = NULL;

UserInfo::UserInfo() : username(""), serverId(TT)
{
    
}

void UserInfo::setUsernameAndServerId(string username, long serverId)
{
    this->username = username;
    this->serverId = serverId;
}

void UserInfo::setUsername(string usernameD)
{
    this->username = username;
}

string UserInfo::getUsername() const
{
    return username;
}

UserInfo * UserInfo::getInstance()
{
    
    if (userInfoInstance == NULL) {
        userInfoInstance = new UserInfo();
    }
    
    return userInfoInstance;
}

void UserInfo::setHasPhone(bool hasphone)
{
    this->hasphone = hasphone;
}

bool UserInfo::getHasPhone()
{
    return hasphone;
}

void UserInfo::setUserType(int usertype)
{
    this->usertype = usertype;
}

int UserInfo::getUserType()
{
    return usertype;
}

long UserInfo::getServerId()
{
    return serverId;
}

void UserInfo::setServerId(long serverId)
{
    this->serverId = serverId;
}


TJPermissionBehaviorType::TJPermissionBehaviorType UserInfo::getTJPermissionBehaviorType(bool permission, LineType::LineType lineType)
{
    
    if (permission) {
        return TJPermissionBehaviorType::HasPermission;
    }
    if (username == ""){
        return TJPermissionBehaviorType::ForGuest;
    }
    if (lineType == LineType::L60m)
    {
        if (hasphone){
            return TJPermissionBehaviorType::AfterTrial;
        }
        return TJPermissionBehaviorType::ForThirdPartyNoPhone;
    }
    if (usertype > 2) {
        return TJPermissionBehaviorType::AfterDeposit;
    }
    return TJPermissionBehaviorType::AfterTrial;
}

QKPermissionBehaviorType::QKPermissionBehaviorType UserInfo::getQKPermissionBehaviorType(bool permission, LineType::LineType lineType)
{
    if (permission) {
        return QKPermissionBehaviorType::HasPermission;
    }
    if (!hasphone && username != ""){
        return QKPermissionBehaviorType::NoPhone;
    }
    return QKPermissionBehaviorType::NoPermission;
}

QKTPermissionBehaviorType::QKTPermissionBehaviorType UserInfo::getQKTPermissionBehaviorType(bool permission, LineType::LineType lineType)
{
    if (permission) {
        return QKTPermissionBehaviorType::HasPermission;
    }
    return QKTPermissionBehaviorType::NoPermission;
}

GameMatrixPermissionBehaviorType::GameMatrixPermissionBehaviorType UserInfo::getGameMatrixPermissionBehaviorType(bool permission, LineType::LineType lineType)
{
    if (permission) {
        return GameMatrixPermissionBehaviorType::HasPermission;
    }
    if (username == ""){
        return GameMatrixPermissionBehaviorType::ForGuest;
    }
    else {
        return GameMatrixPermissionBehaviorType::ForUser;
    }
}

HJJTPermissionBehaviorType::HJJTPermissionBehaviorType UserInfo::getHJJTPermissionBehaviorType(bool permission, LineType::LineType lineType)
{
    if (permission) {
        return HJJTPermissionBehaviorType::ForGJ;
    }
    return HJJTPermissionBehaviorType::ForGJ;
}

LSPPermissionBehaviorType::LSPPermissionBehaviorType UserInfo::getLSPPermissionBehaviorType(int permissionType, LineType::LineType lineType)
{
    if (permissionType == 1 || permissionType == 2) {
        return LSPPermissionBehaviorType::HasPermission;
    }
    return LSPPermissionBehaviorType::NoPermission;
}

